<?php
class View_Administration_User_Roles extends View_Administration_User
{
	/**
	 *	Builds Locations View.
	 *	@access		public
	 *	@return		string
	 */
	public function buildContent( $page = 'edit')
	{
		$logic		= new Logic_User();
		$config		= $this->registry->get( 'config' );
		$request	= $this->registry->get( 'request' );
		$session	= $this->registry->get( 'session' );
		$auth		= $this->registry->get( 'auth' );
		$words		= $this->words['user']['editUserRoles'];
		$userId		= $request->get( 'userId' );

		$roles		= Logic_Role::getUserRoles( FALSE, $userId );
		$assigned	= array();
		if( $page == 'edit' )
			foreach( $roles as $roleId => $roleTitle )
				$assigned[]	= $roleId;
		else
			$assigned = $session->get( 'add_user_roles' );
		$all		= Logic_Role::getRoles( FALSE );

		$has	= array();
		$more	= array();
		foreach( $all as $roleId => $roleTitle )
		{
			if( in_array( $roleId, $assigned ) )
				$has[$roleId]	= $roleTitle;
			else
				$more[$roleId]	= $roleTitle;
		}
		$sources	= array(
			'opt_remove'	=> $has,
			'opt_add'		=> $more,
			);

		$ui	= $this->buildForm( 'administration/user', 'editUserRoles', 'user', 'editUserRoles', array(), $sources );

		$button_add		= $this->html->Button( 'addUserRoles', $words['button_add'], 'but add' );
		$button_remove	= $this->html->Button( 'removeUserRoles', $words['button_remove'], 'buthot remove' );

		$ui['field_button_add']		= $this->html->Field( '', $button_add );
		$ui['field_button_remove']	= $this->html->Field( '', $button_remove );

		$ui['form']		= $this->html->Form( 'editUserRoles' );
		$ui['caption']		= $this->html->TableCaption( $words['caption'], $page );
		$ui['colgroup']		= $this->html->ColumnGroup( $words['colgroup'] );
		$ui['heading']		= $words['heading'];
		return $this->loadTemplate( 'administration.user.roles', $ui );
	}
}
?>